
import store from '@/store'
import api from '@/api'
import config from '@/config'

export function navToFace () {
  wx.navigateToMiniProgram({
    appId: config.faceAppId,
    path: 'pages/authenticate/login/login-face/login-face',
    extraData: {
      responseType: 'code',
      from: 'miniProgram',
      appName: '代表履职通',
      skipbind: 1,
    },
    envVersion: 'release',
    fail (e) {
      uni.showModal({
        title: '失败',
        content: `人脸识别失败 ${e.errMsg}`,
        showCancel: false,
      })
    },
  })
}

export async function handleReturnFromFace (n) {
  if (n.referrerInfo.extraData && n.referrerInfo.extraData.token) {
    await api.certificate({ token: n.referrerInfo.extraData.token })
    store.dispatch('init')
    uni.navigateTo({
      url: '/pages/user/index',
    })
  }
}
